<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <title>忘记密码</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="css/shop.css">
    <link rel="stylesheet" href="css/weui.min.css">
    <link rel="stylesheet" href="css/jquery-weui.min.css">
    <script src="js/jquery-2.1.4.js"></script>
    <script src="js/jquery-weui.js"></script>
    <script type="text/javascript" src="js/city-picker.js" charset="utf-8"></script>
    <script src="wxJs/utils/contain.js"></script>
    <script src="wxJs/utils/storage.js"></script>
</head>

<body>
<div class="header">
    <a class="haader-left" href="javascript:window.history.go(-1)"><i class="iconfont icon-left"></i></a>
    <div class="haader-content">忘记密码</div>
    <div class="haader-right">
        <!-- <a href="give_integral.html"><i class="iconfont icon-add"></i></a> -->
    </div>
</div>
<div class="weui-cells">
    <div class="weui-cell weui-cell_select weui-cell_select-before">
        <div class="weui-cell__hd">
            <select class="weui-select" name="select2">
                <option value="1">+86</option>
            </select>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入手机号" id="phoneNum" readonly>
        </div>
    </div>
    <div class="weui-cell js_login weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label">验证码</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" placeholder="验证码" id="inpCode">
        </div>
        <div class="weui-cell__ft">
            <button class="weui-vcode-btn getCode">获取验证码</button>
        </div>
    </div>
    <div class="weui-cell js_login">
        <div class="weui-cell__hd"><label class="weui-label">新密码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="password" placeholder="请输入新密码" id="newMM1"  maxlength="6" oninput="setNumType(this)">
        </div>
    </div>
    <div class="weui-cell js_login">
        <div class="weui-cell__hd"><label class="weui-label">确认密码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="password" placeholder="请输入新密码" id="newMM2"  maxlength="6" oninput="setNumType(this)">
        </div>
    </div>
    <div class="btn-contain mt10"><a href="javascript:;" class="weui-btn js_reset weui-btn_primary">重置密码</a></div>
</div>
<script>

    var userId = GetQueryString("userId");
    if (!userId || userId == 0) {
        window.history.back(-1);
    }
    var userInfo = getUserInfo(userId)
    if (userInfo.phoneNum){
        $("#phoneNum").val(userInfo.phoneNum);
    } else {
        window.history.back(-1);
    }

    var ran;
    /*发送验证码*/
    $(".getCode").on("click", function () {
        $.toast("验证码已发送至手机")
        var url = getWeiContextPath() + "/wx/VipUser/queryCode"
        $.ajax({
            type: "POST",
            cache: false,
            data: {phone: userInfo.phoneNum},
            async: false,
            url: url,
            success: function (res) {
                console.log(res.ran)
                ran = res.ran;
            },
            error: function (res) {
                $.toast(res.msg, "forbidden")
            }
        });
    })
    /*修改保存按钮*/
    $(".js_reset").on("click", function () {
        var inpCode = $("#inpCode").val().trim();
        if ( !ran) {
            $.toast("未发送验证码", "forbidden")
            return false;
        }
        if (inpCode != ran) {
            $.toast("验证码有误", "forbidden")
            return false;
        }

        var newMM1 = $("#newMM1").val().trim()
        var newMM2 = $("#newMM2").val().trim()
        if (newMM1 && newMM2 && newMM1 == newMM2) {
            $.post(getWeiContextPath() + "/wx/VipUser/setPayNumber", {
                wxUserId: userId,
                payNumber: newMM1
            }, function (res) {
                $.toast("密码重置成功", function () {
                    window.location.replace("me.html?userId=" + userId)
                })
            })
        } else {
            $.toast("新密码两次输入不一致", "forbidden")
        }
    })
    /*输入数字*/
    function setNumType(_this) {
        var num = $(_this).val()
        $(_this).val(num.replace(/[^\d]/g,''))
    }
</script>
</body>

</html>